package com.personal.dao;


import com.personal.domain.Enterprise;
import com.personal.util.partDisplay.EnterprisePart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface EnterpriseDao {

    @Select("select * from enterprisecustomer")
    List<Enterprise> selectAll();

    @Select("select id,customerName,customerCode,underRent,attributionRange,mainDockingMan,mainDockingManPhone from enterprisecustomer")
//    @Results({
//            @Result(column = "mainDockingMan",property = "dockingPerson"),
//            @Result(column = "mainDockingManPhone",property = "phoneNumber")
//    })
    List<EnterprisePart> selectPartAll();

    @Select("select id,customerName,customerCode,underRent,attributionRange,mainDockingMan,mainDockingManPhone " +
            "from enterprisecustomer where customerName like CONCAT('%',#{customerName},'%') and customerCode like CONCAT('%',#{customerCode},'%')")
    List<EnterprisePart> selectPartByKey(String customerName,String customerCode);


    @Insert("insert into enterprisecustomer (id,affiliatedProject, customerName, customerAbbreviation, customerType," +
            "                                        customerCode, attributionRange, mainDockingMan, mainDockingManPhone," +
            "                                        documentType, documentCode, enterpriseUnifiedCreditCode, legalRepresentative," +
            "                                        legalRepresentativePhone, legalRepresentativeHousehold, enterpriseTelephone," +
            "                                        registrationStatus, establishmentDate, enterpriseWebsite, registeredCapital," +
            "                                        paidCapital, enterpriseEmail, customerServiceManager, customerServiceManagerPhone," +
            "                                        emergencyContact, emergencyContactPhone, financialCustomerCode, underRent," +
            "                                        incubatedEnterprise, blacklist, incubationAgreementDate, businessLicenseAddress," +
            "                                        enterpriseAddress, product, businessScope, remark, attachments) value " +
            "                                     (null,#{affiliatedProject},#{customerName},#{customerAbbreviation},#{customerType}," +
            "                                      #{customerCode},#{attributionRange},#{mainDockingMan},#{mainDockingManPhone}," +
            "                                      #{documentType},#{documentCode},#{enterpriseUnifiedCreditCode},#{legalRepresentative}," +
            "                                      #{legalRepresentativePhone},#{legalRepresentativeHousehold},#{enterpriseTelephone}," +
            "                                      #{registrationStatus},#{establishmentDate},#{enterpriseWebsite},#{registeredCapital}," +
            "                                      #{paidCapital},#{enterpriseEmail},#{customerServiceManager},#{customerServiceManagerPhone}," +
            "                                      #{emergencyContact},#{emergencyContactPhone},#{financialCustomerCode},#{underRent}," +
            "                                      #{incubatedEnterprise},#{blacklist},#{incubationAgreementDate},#{businessLicenseAddress}," +
            "                                      #{enterpriseAddress},#{product},#{businessScope},#{remark},#{attachments})")
    int add(Enterprise enterprise);


    @Select("select * from enterprisecustomer where id=#{id}")
    Enterprise getUpdateData(int id);

    @Update("update enterprisecustomer set affiliatedProject=#{affiliatedProject},customerName=#{customerName},customerAbbreviation=#{customerAbbreviation}," +
            "            customerType=#{customerType},customerCode=#{customerCode},attributionRange=#{attributionRange}," +
            "            mainDockingMan=#{mainDockingMan},mainDockingManPhone=#{mainDockingManPhone}," +
            "            documentType=#{documentType},documentCode=#{documentCode},enterpriseUnifiedCreditCode=#{enterpriseUnifiedCreditCode}," +
            "            legalRepresentative=#{legalRepresentative},legalRepresentativePhone=#{legalRepresentativePhone}," +
            "            legalRepresentativeHousehold=#{legalRepresentativeHousehold},enterpriseTelephone=#{enterpriseTelephone}," +
            "            registrationStatus=#{registrationStatus},establishmentDate=#{establishmentDate}," +
            "            EnterpriseWebsite=#{EnterpriseWebsite},registeredCapital=#{registeredCapital}," +
            "            paidCapital=#{paidCapital},enterpriseEmail=#{enterpriseEmail},customerServiceManager=#{customerServiceManager}," +
            "            customerServiceManagerPhone=#{customerServiceManagerPhone},emergencyContact=#{emergencyContact}," +
            "            emergencyContactPhone=#{emergencyContactPhone},financialCustomerCode=#{financialCustomerCode},underRent=#{underRent}," +
            "            incubatedEnterprise=#{incubatedEnterprise},blacklist=#{blacklist},incubationAgreementDate=#{incubationAgreementDate}," +
            "            businessLicenseAddress=#{businessLicenseAddress},enterpriseAddress=#{enterpriseAddress}," +
            "            product=#{product},businessScope=#{businessScope},remark=#{remark},attachments=#{attachments} where id=#{id}")
    int update(Enterprise enterprise);



    @Delete("delete from enterprisecustomer where id=#{id}")
    int delete(int id);



}
